home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / cat.3 / CrtCommand.3 < prev    next >
Encoding:
Text File  |  1995-07-26  |  15.0 KB  |  265 lines

  1.  
  2.  
  3.  
  4.      TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333))))         TTTTccccllll (((( ))))         TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333))))
  5.  
  6.  
  7.  
  8.      _________________________________________________________________
  9.  
  10.      NNNNAAAAMMMMEEEE
  11.           Tcl_CreateCommand,  Tcl_DeleteCommand,   Tcl_GetCommandInfo,
  12.           Tcl_SetCommandInfo - implement new commands in C
  13.  
  14.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  15.           ####iiiinnnncccclllluuuuddddeeee <<<<ttttccccllll....hhhh>>>>
  16.  
  17.           TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd(_i_n_t_e_r_p, _c_m_d_N_a_m_e, _p_r_o_c, _c_l_i_e_n_t_D_a_t_a, _d_e_l_e_t_e_P_r_o_c)
  18.  
  19.           int
  20.           TTTTccccllll____DDDDeeeelllleeeetttteeeeCCCCoooommmmmmmmaaaannnndddd(_i_n_t_e_r_p, _c_m_d_N_a_m_e)
  21.  
  22.           int                                                           |
  23.           TTTTccccllll____GGGGeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo(_i_n_t_e_r_p, _c_m_d_N_a_m_e, _i_n_f_o_P_t_r)                  |
  24.  
  25.           int                                                           |
  26.           TTTTccccllll____SSSSeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo(_i_n_t_e_r_p, _c_m_d_N_a_m_e, _i_n_f_o_P_t_r)                  |
  27.  
  28.      AAAARRRRGGGGUUUUMMMMEEEENNNNTTTTSSSS
  29.           Tcl_Interp          *_i_n_t_e_r_p           (in)      Interpreter
  30.                                                           in  which to
  31.                                                           create   new
  32.                                                           command.
  33.  
  34.           char                *_c_m_d_N_a_m_e          (in)      Name      of
  35.                                                           command.
  36.  
  37.           Tcl_CmdProc         *_p_r_o_c             (in)      Implementation
  38.                                                           of       new
  39.                                                           command:
  40.                                                           _p_r_o_c will be
  41.                                                           called
  42.                                                           whenever
  43.                                                           _c_m_d_N_a_m_e   is
  44.                                                           invoked as a
  45.                                                           command.
  46.  
  47.           ClientData          _c_l_i_e_n_t_D_a_t_a        (in)      Arbitrary
  48.                                                           one-word
  49.                                                           value     to
  50.                                                           pass to _p_r_o_c
  51.                                                           and
  52.                                                           _d_e_l_e_t_e_P_r_o_c.
  53.  
  54.           Tcl_CmdDeleteProc   *_d_e_l_e_t_e_P_r_o_c       (in)      Procedure to
  55.                                                           call  before
  56.                                                           _c_m_d_N_a_m_e   is
  57.                                                           deleted from
  58.                                                           the
  59.                                                           interpreter;
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 7/10/95)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333))))         TTTTccccllll (((( ))))         TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333))))
  71.  
  72.  
  73.  
  74.                                                           allows   for
  75.                                                           command-
  76.                                                           specific
  77.                                                           cleanup.  If
  78.                                                           NULL,   then
  79.                                                           no procedure
  80.                                                           is    called
  81.                                                           before   the
  82.                                                           command   is
  83.                                                           deleted.
  84.  
  85.           Tcl_CmdInfo         *_i_n_f_o_P_t_r          (in/out)  Pointer   to  |
  86.                                                           structure  |
  87.                                                           containing  |
  88.                                                           various  |
  89.                                                           information  |
  90.                                                           about  a Tcl  |
  91.                                                           command.
  92.      _________________________________________________________________
  93.  
  94.  
  95.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  96.           TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd  defines  a  new  command  in  _i_n_t_e_r_p  and
  97.           associates it with procedure _p_r_o_c such that whenever _c_m_d_N_a_m_e
  98.           is invoked as a Tcl command (via a call to TTTTccccllll____EEEEvvvvaaaallll) the Tcl
  99.           interpreter will call _p_r_o_c to process the command.  If there
  100.           is  already  a   command   _c_m_d_N_a_m_e   associated   with   the
  101.           interpreter,  it is deleted.  _P_r_o_c should have arguments and
  102.           result that match the type TTTTccccllll____CCCCmmmmddddPPPPrrrroooocccc:
  103.                typedef int Tcl_CmdProc(
  104.                     ClientData _c_l_i_e_n_t_D_a_t_a,
  105.                     Tcl_Interp *_i_n_t_e_r_p,
  106.                     int _a_r_g_c,
  107.                     char *_a_r_g_v[]);
  108.           When _p_r_o_c is invoked the _c_l_i_e_n_t_D_a_t_a  and  _i_n_t_e_r_p  parameters
  109.           will  be copies of the _c_l_i_e_n_t_D_a_t_a and _i_n_t_e_r_p arguments given
  110.           to TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd.  Typically, _c_l_i_e_n_t_D_a_t_a  points  to  an
  111.           application-specific  data  structure that describes what to
  112.           do when the command procedure is  invoked.   _A_r_g_c  and  _a_r_g_v
  113.           describe  the  arguments  to  the  command,  _a_r_g_c giving the
  114.           number of arguments (including the command  name)  and  _a_r_g_v
  115.           giving  the  values  of  the arguments as strings.  The _a_r_g_v
  116.           array will contain _a_r_g_c+1  values;  the  first  _a_r_g_c  values
  117.           point to the argument strings, and the last value is NULL.
  118.  
  119.           _P_r_o_c must return an integer  code  that  is  either  TTTTCCCCLLLL____OOOOKKKK,
  120.           TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR,  TTTTCCCCLLLL____RRRREEEETTTTUUUURRRRNNNN, TTTTCCCCLLLL____BBBBRRRREEEEAAAAKKKK, or TTTTCCCCLLLL____CCCCOOOONNNNTTTTIIIINNNNUUUUEEEE.  See the
  121.           Tcl overview man page for details on what these codes  mean.
  122.           Most  normal  commands will only return TTTTCCCCLLLL____OOOOKKKK or TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR.
  123.           In addition, _p_r_o_c must set  _i_n_t_e_r_p->_r_e_s_u_l_t  to  point  to  a
  124.           string value; in the case of a TTTTCCCCLLLL____OOOOKKKK return code this gives
  125.           the result of the command, and in the case of  TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR  it
  126.  
  127.  
  128.  
  129.      Page 2                                          (printed 7/10/95)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333))))         TTTTccccllll (((( ))))         TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333))))
  137.  
  138.  
  139.  
  140.           gives   an   error  message.   The  TTTTccccllll____SSSSeeeettttRRRReeeessssuuuulllltttt  procedure
  141.           provides an easy interface for  setting  the  return  value;
  142.           for  complete  details  on  how  the _i_n_t_e_r_p->_r_e_s_u_l_t field is
  143.           managed, see the TTTTccccllll____IIIInnnntttteeeerrrrpppp man  page.   Before  invoking  a
  144.           command  procedure, TTTTccccllll____EEEEvvvvaaaallll sets _i_n_t_e_r_p->_r_e_s_u_l_t to point to
  145.           an empty string, so simple  commands  can  return  an  empty
  146.           result by doing nothing at all.
  147.  
  148.           The contents of the _a_r_g_v array belong to  Tcl  and  are  not  |
  149.           guaranteed  to  persist  once _p_r_o_c returns:  _p_r_o_c should not  |
  150.           modify them, nor  should  it  set  _i_n_t_e_r_p->_r_e_s_u_l_t  to  point  |
  151.           anywhere  within  the  _a_r_g_v values.  Call TTTTccccllll____SSSSeeeettttRRRReeeessssuuuulllltttt with  |
  152.           status TTTTCCCCLLLL____VVVVOOOOLLLLAAAATTTTIIIILLLLEEEE if you want to return something from the  |
  153.           _a_r_g_v array.
  154.  
  155.           _D_e_l_e_t_e_P_r_o_c will be invoked when  (if)  _c_m_d_N_a_m_e  is  deleted.
  156.           This  can  occur  through  a  call  to  TTTTccccllll____DDDDeeeelllleeeetttteeeeCCCCoooommmmmmmmaaaannnndddd or
  157.           TTTTccccllll____DDDDeeeelllleeeetttteeeeIIIInnnntttteeeerrrrpppp, or by replacing _c_m_d_N_a_m_e in another call to
  158.           TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd.  _D_e_l_e_t_e_P_r_o_c is invoked before the command
  159.           is deleted, and gives  the  application  an  opportunity  to
  160.           release   any   structures   associated  with  the  command.
  161.           _D_e_l_e_t_e_P_r_o_c should have arguments and result that  match  the
  162.           type TTTTccccllll____CCCCmmmmddddDDDDeeeelllleeeetttteeeePPPPrrrroooocccc:
  163.  
  164.                typedef void Tcl_CmdDeleteProc(ClientData _c_l_i_e_n_t_D_a_t_a);
  165.  
  166.           The _c_l_i_e_n_t_D_a_t_a argument will be the same as  the  _c_l_i_e_n_t_D_a_t_a
  167.           argument passed to TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd.
  168.  
  169.           TTTTccccllll____DDDDeeeelllleeeetttteeeeCCCCoooommmmmmmmaaaannnndddd  deletes  a   command   from   a   command
  170.           interpreter.   Once  the  call completes, attempts to invoke
  171.           _c_m_d_N_a_m_e in _i_n_t_e_r_p will result in errors.  If  _c_m_d_N_a_m_e  isn't
  172.           bound  as  a  command  in _i_n_t_e_r_p then TTTTccccllll____DDDDeeeelllleeeetttteeeeCCCCoooommmmmmmmaaaannnndddd does
  173.           nothing and returns -1;  otherwise it returns 0.  There  are
  174.           no  restrictions  on  _c_m_d_N_a_m_e:   it  may refer to a built-in
  175.           command,  an  application-specific   command,   or   a   Tcl
  176.           procedure.
  177.  
  178.           TTTTccccllll____GGGGeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo  checks  to  see  whether   its   _c_m_d_N_a_m_e  |
  179.           argument  exists  as  a  command  in _i_n_t_e_r_p.  If not then it  |
  180.           returns  0.   Otherwise  it  places  information  about  the  |
  181.           command  in  the structure pointed to by _i_n_f_o_P_t_r and returns  |
  182.           1.   Tcl_CmdInfo  structures   have   fields   named   _p_r_o_c,  |
  183.           _c_l_i_e_n_t_D_a_t_a,  and  _d_e_l_e_t_e_P_r_o_c, which have the same meaning as  |
  184.           the corresponding arguments to TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd.  There  is  |
  185.           also  a  field  _d_e_l_e_t_e_D_a_t_a, which is the ClientData value to  |
  186.           pass to _d_e_l_e_t_e_P_r_o_c;  it is normally the same  as  _c_l_i_e_n_t_D_a_t_a  |
  187.           but  may  be  set independently using the TTTTccccllll____SSSSeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo  |
  188.           procedure.                                                    |
  189.  
  190.           TTTTccccllll____SSSSeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo is used  to  modify  the  procedures  and  |
  191.           ClientData  values  associated  with a command.  Its _c_m_d_N_a_m_e  |
  192.  
  193.  
  194.  
  195.      Page 3                                          (printed 7/10/95)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333))))         TTTTccccllll (((( ))))         TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd((((3333))))
  203.  
  204.  
  205.  
  206.           argument is the name  of  a  command  in  _i_n_t_e_r_p.   If  this  |
  207.           command    exists   then   TTTTccccllll____SSSSeeeettttCCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo   returns   0.  |
  208.           Otherwise, it copies the information from *_i_n_f_o_P_t_r to  Tcl's  |
  209.           internal structure for the command and returns 1.  Note that  |
  210.           this  procedure  allows  the  ClientData  for  a   command's  |
  211.           deletion  procedure  to  be given a different value than the  |
  212.           ClientData for its command procedure.
  213.  
  214.  
  215.      KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS
  216.           bind, command, create, delete, interpreter
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                                          (printed 7/10/95)
  262.  
  263.  
  264.  
  265.